package com.cmdi.controller;

import com.cmdi.gateway.config.GatewayDynamicRouteService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;




/**
 * @Description: 获取sentinel的限流规则
 * @Author: gaozb
 */
@Slf4j
@RestController
@RequestMapping("/route")
public class GatewayRouteController {
    @Value("${gw.key:abcd}")
    private String key;

    @Autowired
    private GatewayDynamicRouteService gatewayDynamicRouteService;


    @GetMapping("/update")
    public Boolean update(@RequestParam("gwkey") String gwKey) {
        if(gwKey.equals(key)) {
            log.info("updating.....................");
            gatewayDynamicRouteService.notifyChanged();
            return true;
        }
        return false;
    }

//    @PostMapping("/add")
//    public String create(@RequestBody RouteDefinition entity) {
//        int result = gatewayDynamicRouteService.add(entity);
//        return String.valueOf(result);
//    }
//
//    @PostMapping("/update")
//    public String update(@RequestBody RouteDefinition entity) {
//        int result = gatewayDynamicRouteService.update(entity);
//        return String.valueOf(result);
//    }
//
//    @GetMapping("/delete")
//    public Mono<ResponseEntity<Object>> delete(@RequestParam("id") String id) {
//        return gatewayDynamicRouteService.delete(id);
//    }
//    @GetMapping("/get")
//    public Flux<RouteDefinition> get() {
//        Flux<RouteDefinition> routeDefinitionFlux = gatewayDynamicRouteService.get();
//        routeDefinitionFlux.subscribe(va -> {
//            System.out.println(va);
//        });
//        return routeDefinitionFlux;
//    }
}